package cn.edu.hrbcu.everywhereapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import cn.edu.hrbcu.everywhereapp.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

import cn.edu.hrbcu.everywhereapp.entity.BusLocation;

//
public class BusLocationApapter extends ArrayAdapter<BusLocation> {
    private List<BusLocation> busLocations = null;

    public BusLocationApapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<BusLocation> objects) {
        super(context, resource, textViewResourceId, objects);
        busLocations = objects;
    }

    @Override
    public int getCount() {
        return busLocations.size();
    }

    @Nullable
    @Override
    public BusLocation getItem(int position) {
        return busLocations.get(position);
    }

    @Override
    public int getPosition(@Nullable BusLocation item) {
        return super.getPosition(item);
    }

    @Override
    public long getItemId(int position) {
        return busLocations.get(position).getId();
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
//        获取当前子项内容
        BusLocation busLocation = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.buslocation_item,parent,false);
        TextView busname = view.findViewById(R.id.bus_name);
        TextView buslicense = view.findViewById(R.id.bus_license);
        TextView busstarttime = view.findViewById(R.id.bus_starttime);
        busname.setText(busLocation.getName());
        buslicense.setText(busLocation.getLicense());
        busstarttime.setText("19:10");
        return view;
    }
}
